home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14289 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  6.2 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character
  5. Date: 12 Apr 1996 14:26:20 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4kmhpsINN7ak@keats.ugrad.cs.ubc.ca>
  8. References: <4kj66f$k0o@ren.cei.net> <4kko80$8np@news.ld.centuryinter.net> <4kkvvsINN8fs@keats.ugrad.cs.ubc.ca> <4kmdsv$ojc@masala.cc.uh.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4kmdsv$ojc@masala.cc.uh.edu>, Spasmo <cosc19z5@Bayou.UH.EDU> wrote:
  12.  >Actually from where I'm standing this is the comp.unix.programmer newsgroup.
  13.  >Don't you love crossposting?  It also means that the response was in fact on
  14.  >topic for us, but apparently not for you--the price of crossposting.
  15.  
  16. Oops, I didn't notice that.
  17.  
  18.  >: >If this requirement is within  C code where the multiple inputs
  19.  >: >screw up the ability to use pipes, then forgive me for not knowing all
  20.  >: >the facts. 
  21.  >: >But,
  22.  >: >The other response using strlen isn't 'wrong'; there are lots of
  23.  >: >ways to skin a cat.
  24.  >
  25.  >: Not if you are being paid by the cat. :) And yes, the strlen() response was
  26.  >: damn wrong. It completely ignored the possiblity that fgets() may return a
  27.  >: string that doesn't have a newline at the end. Just the sort of useless answer
  28.  >: that we don't need on comp.lang.c: incorrect, and is directed at the wrong
  29.  >: question anyway.
  30.  >
  31.  >The strlen() response was right, however it had the possibility of producing
  32.  >undesired effects under certain conditions.  The user wanted a way to remove
  33.  
  34. So how is it right if it had undesired effects under certain conditions?
  35.  
  36.  >newlines, and the response above did it.  Of course in the case of a overly
  37.  
  38. It did not. It removed the last character of the buffer.
  39.  
  40.  >long line, the response would remove a valid character--however the fact
  41.  
  42. And of course, *real* UNIX users don't put lines longer than 79 chars into a
  43. textfile anyway...
  44.  
  45.  >remains that it does remove the newline, and with the addition of some minor
  46.  >code can be made much safer--yet no one has shown the boundary conditions
  47.  >because it's obvious that they can exist, and they are easy to accomodate.
  48.  
  49. If they are easy to accomodate, why not write it properly in the first place?
  50.  
  51. Humor me as to why it is necessary to retain a whole string of data just to
  52. then scan through it to find its length to remove the trailining newline, which
  53. was put there by a standard library function that already scanned the
  54. characters once to _find_ the newline in the first place.
  55.  
  56.  >Also given the application, the conditions that would make the strlen()
  57.  >solution unsafe may not even occur.
  58.  
  59. Is this representative of your general attitude toward software design, or do
  60. you properly reserve it for writing trivial half-a-pagers?
  61.  
  62.  >  So, the details of making the solution
  63.  >more robust are left out.
  64.  
  65. s/more robust/correct/
  66.  
  67. A robust program is one that deals gracefully with bad input, not one that
  68. manages to avoid failure with valid input. A robust program that doesn't want
  69. to deal with long lines will define these as invalid input, and then somehow
  70. handle their occurence.
  71.  
  72.  > Perhaps this is an unwarranted assumption, however
  73.  >it was an assumption that was made--at least in my case.  I was one of the
  74.  >folks who suggested the strlen() solution as I use it when needed (with
  75.  >proper checks of course).  And in case you haven't noticed, the strlen() fix
  76.  >is directed at newline stripping which *IS* the right question.  Go back
  77.  >and re-read the original post.
  78.  
  79. Better yet, why don't I repost it?
  80.  
  81. Hello everybody,
  82.     Is there a function or some sort of way that I could remove '\n' 
  83. charecter form the end of the string. I'm reading from two files, want to 
  84. form one line of text and then have it printed out to stdout. I use fgets to 
  85. read from the file and I noticed that it appends newline char at the end.
  86.     It is important that two lines of text, one from each file, will be 
  87. combined into one and I can't do it because the first string has '\n' added 
  88. to it. I'm picky becauuse the output will be used to feed another program and 
  89. I'm affraid that not properly formatted input may corrupt the process.
  90.     Any suggestions will be greatly appreciated .. Thanks, Art ...
  91.  
  92. Tell me again how I answered the wrong problem with my solution, and how you
  93. answered the right one with your non-solution?
  94.  
  95.  >And yes there are better solutions to the problem.  I like the strchr solution
  96.  >posted by a few folks and will probably use that in preference to 
  97.  >strlen(), however it does not take away from the validity of the original
  98.  
  99. Ah yes. And then there is that fellow who insists that he has never seen a UNIX
  100. system in which it was impossible to do *strchr(string, '\n') = '\0' regardless
  101. of whether there actually is a '\n' character inside ``string''. Simply
  102. brilliant!
  103.  
  104.  >And using UNIX commands to achieve what you need instead of C is far
  105.  >more elegant, far less typing, far more robust, and far easier than
  106.  >any code you can write.  Get a grip the guy above is discussing using
  107.  
  108. I agree, but sadly, I had not noticed this was crossposted to a UNIX
  109. newsgroup.
  110.  
  111.  >UNIX utilities instead of re-inventing the wheel.  And he's got a very
  112.  
  113. Right, but in comp.lang.c, not everyone is a UNIX user. 
  114.  
  115.  >valid point.  With all the beautiful tools available under UNIX we can
  116.  >get a lot done without having to write any code.  As it stands people
  117.  >jump into a compiler to fix problems that can be better fixed without
  118.  >writing software.  He has a very valid point.  You'd do well to stop
  119.  >babbling and start listening.
  120.  
  121. I know my UNIX tools well, but I'm not going to push the beautiful beasties
  122. onto Mac, OS/2, Windows or VMS programmers that may be reading comp.lang.c. I
  123. do use UNIX and advocate it and its tools elsewhere, like comp.os.*.advocacy.
  124.  
  125. Other than that I can _babble_ all I want---I earn that right by posting
  126. correct answers that are tested to work, and get the poor newbie on the right
  127. track, which is what these two newsgroups are for. I never flamed the one who
  128. started this thread with a honest programming question, just the incorrect,
  129. useless help he was getting which is worse than no help at all.
  130.  
  131. Why should I _listen_ to you? You can't even post a solution to a trivial
  132. problem without overcomplicating it and buggering it up.  
  133. -- 
  134.  
  135.